        

        var actHarvestStore = new Ext.data.JsonStore({
			url: '/weihe/getAct_harvest',
			root: 'datas',
			fields : [{
						name:'ActHarvestId',mapping:'id'
					},{
     				   name:'ActHarvestDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'ActHarvestType',mapping:'type'
					},{
						name:'ActHarvestActRate',mapping:'actRate'
					},{
						name:'ActHarvestDiffPrice',mapping:'diffPrice'
					},{
						name:'ActHarvestSale',mapping:'sale'
				    },{
				    	name:'ActHarvestNetProfit',mapping:'netProfit'
				    }],
					listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_harvest',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});

        

actHarvests = function(){
  return{
     
	
	 actHarvestGrid : function(){

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
	    var pageToolBar = new Ext.PagingToolbar({
			pageSize : 12,
			store : actHarvestStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
			});
		 
	   var actHarvestGrid = new Ext.grid.GridPanel({
		   id:'actHarvestGrid',
		   title : '代理业务成果表',
		   region : 'center',
		   height :300,
		   minColumnWidth : 50,
		   tbar:["-",'新增记录:',new Ext.form.TextField({id:'ym',name:'query',value:(new Date()).format('Y-m'),width:'60',regex : /^\d{4}-(?:0[1-9]|1[0-2])$/,
		    regexText:'请输入有效日期格式为2010-01' }),new Ext.Button({text:'提交',handler : function() {
			   					progressConsole();
								Ext.Ajax.request({
									url : '/weihe/addAct_harvest',
									success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.success) {
										if (json.deny) {
											Ext.Msg.alert('消息', json.msg);
										}else{
											Ext.Msg.alert('消息', json.msg, function() {
													Ext.getCmp("actHarvestGrid").getStore().baseParams = {'query':Ext.getCmp('ym').getValue()};
			   										Ext.getCmp("actHarvestGrid").getStore().load({params : {start : 0, limit : 12}});
											});
										}
									  }else{
										Ext.Msg.alert('消息', json.msg);
									  }
									},
									failure : function() {
										Ext.Msg.alert('错误', '删除失败!');
									},
									params : 'sd=' + Ext.getCmp('ym').getValue()
								});
			   		
		   		}})
		   ,"-",'查看年份:',new Ext.form.TextField({id:'year',name:'query',value:(new Date()).format('Y'),width:'50'}),new Ext.Button({text:'提交',handler : function() {
			   					Ext.getCmp("actHarvestGrid").getStore().baseParams = {'query':Ext.getCmp('year').getValue()};
			   					Ext.getCmp("actHarvestGrid").getStore().load({params : {start : 0, limit : 12}});
		   		}})
		   ,"-"],

		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : actHarvestStore,
		   columns: [
		             {header : '日期', dataIndex : 'ActHarvestDate', menuDisabled : true,renderer:function(value, cellmeta, record, rowIndex){
							if(value != null&&(rowIndex%6==0)){
									return value.format('Y年m月');
								}else if (value != null&&((rowIndex+1)%6==0)){
									return '本月合计';
								}else if(value == null){
									return '本年累计';
								}else{
									return "";
								}
		             }},
		             {header : '商品类别', dataIndex : 'ActHarvestType'},
		             {header : '营业额', dataIndex : 'ActHarvestSale'},
		             {header : '代理费', dataIndex : 'ActHarvestActRate'},
		             {header : '中间差价', dataIndex : 'ActHarvestDiffPrice'},
		             {header : '纯利', dataIndex : 'ActHarvestNetProfit'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   if(record.get('ActHarvestType')!=""){
			   	  Ext.getCmp("actHarvestForm").form.loadRecord(record);
			  	  var d = record.get('ActHarvestDate').format('Y-m')+"";
			  	  Ext.getCmp("actHarvestForm").form.findField('sd').setValue(d);
			   	}
			   	else{
			   		 Ext.getCmp("actHarvestForm").form.reset();
			   		Ext.Msg.alert('提示','不能修改合计数据!');
			   	}
			   	
			   }
		   
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return actHarvestGrid;
	},
	actHarvestForm : function(){
		var button_add = new Ext.Button({
			text : '添加/修改',
			handler : function() {
					progressConsole();
				if(actHarvestForm.form.isValid()){ 	
						actHarvestForm.form.submit({
						  url : '/weihe/updateAct_harvest',
						   success : function(form, action) {
							  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
							   }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									   actHarvestForm.form.reset();
									   Ext.getCmp("actHarvestGrid").getStore().reload();
								});
							  }
						    }
					    });
				}else{
					Ext.Msg.alert('提示','请输入相关内容');
				}
					}
		});

	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			actHarvestForm.form.reset();
			actHarvestForm.buttons[0].setText('添加');
		}
	});


	var  actHarvestForm = new Ext.form.FormPanel({
		id : 'actHarvestForm',
		title : '代理业务信息',
		frame : true,
		width : 300,
		region : 'east',
		autoScroll : true,
		collapseMode :'mini',
		collapsible : true,
		labelAlign : 'right',
		labelWidth : 60,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  
			id:'ActHarvestId',
			xtype : 'hidden',  
			name : 'actHarvest.id'
		},{
			id:'ActHarvestDate',
			fieldLabel : '日期',
			name : 'sd',
			readOnly : true
		},{
			  id : 'ActHarvestType',
			  fieldLabel : '商品类别',
		      name : 'actHarvest.type',
			  readOnly : true
		   },{
			id:'ActHarvestSale',
			fieldLabel : '营业额',
			name : 'actHarvest.sale',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'ActHarvestActRate',
			fieldLabel : '代理费',
			name : 'actHarvest.actRate',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'ActHarvestDiffPrice',
			fieldLabel : '中间差价',
			name : 'actHarvest.diffPrice',
			regex : /^-?\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		}],
		buttons : [button_add,button_clear]
	});
		return  actHarvestForm;
	}
  }
}();








